package com.net.ip01;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 没有封装端口
 *
 * @author jiangbang
 * @date 2016/7/21
 */
public class InetAddressDemo {
    public static void main(String[] args) throws UnknownHostException {
        //使用getLocalhost方法创建InteAddress对象
        InetAddress inetAddress = InetAddress.getLocalHost();
        System.out.println(inetAddress.getHostAddress());//返回：192.168.1.100
        System.out.println(inetAddress.getHostName());//输出计算机名
        //根据域名得到inetAddress对象
        inetAddress = InetAddress.getByName("www.analysys.com");
        System.out.println(inetAddress.getHostAddress());//返回：192.168.1.100
        System.out.println(inetAddress.getHostName());//www.analysys.com
        //根据域名得到inetAddress对象
//        inetAddress = InetAddress.getByName("96.45.82.217");
//        System.out.println(inetAddress.getHostAddress());//返回：192.168.1.100
//        System.out.println(inetAddress.getHostName());//输出计算机名
    }
}
